<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>会员任务</title> $!{include("import_js_css.html")}
</head>
<body>
	$!{include("header.html")}
	<div class="container menu_all">
		<div class="panel panel-info">
			<!--#var(Member member)-->
			<input type="hidden" value="${member.memberid}" id="hidMemberId" /> $!{include("memberHeader.html")}
			<div id="div_result_member" style="padding: 15px;">
				<div class="panel">
					$!{include("member_info_tab.html")}
					<div class="tdl_center">
						<div class="panel-hxcd-info">
								<div class="panel-heading panel-result-title">
									<h3 class="panel-title">进行的任务</h3>
									&nbsp;
									<div class="btn-group btn-gp-default">
										<button id="btn_add" onclick="addTask()" type="button" class="btn btn-default panel-radius-left">添加</button>
										<button id="btn_edit" onclick="editTask()" type="button" class="btn btn-default panel-radius-none">修改</button>
										<button id="btn_delete" type="button" class="btn btn-default panel-radius-right">删除</button>
									</div>
								</div>
								<!-- #set(PaginatedList<HomePageTaskRecord> oningTasks) -->
								<!--#if(oningTasks)-->
								<table id="td_tb_task" class="table table-bordered table-hover table-condensed tb" style="text-align: center; border-bottom: 1px solid #DDDDDD;table-layout: fixed;">
									<tr>
										<td width="40px;"><input id="chkallIds" type="checkbox" /></td>
										<td width="80px;">工作安排</td>
										<td width="100px;">任务名称</td>
										<td width="80px;">负责人</td>
										<td width="100px;">到期时间</td>
										<td width="80px;">会员名</td>
										<td>备注</td>
										<td width="125px;">创建时间</td>
										<td width="120px;">操作</td>
									<tr>
										<!--#for(HomePageTaskRecord record : oningTasks)-->
									<tr>
										<td><input name="chk_name" type="checkbox" value="${record.rwbh}" /></td>
										<td><a href="yueyogaAdmin/toViewTask.jhtml?taskId=${record.rwbh}">${record.gzap}</a></td>
										<td>${record.rwmz}<input type="hidden" value="${record.rwbh}" id="hidTaskId" /></td>
										<td>${record.rwfzr}</td>
										<td>${record.dqsj}</td>
										<td>${record.hyxm}</td>
										<td width="15%" style="word-break: break-all; word-wrap:break-word;">
										<!-- #set(bz = record.rwbz,slh='...') -->
										<!-- #if(bz==null||bz == "") -->
										&nbsp;
										<!-- #else -->
										<span title="${bz}">${bz}</span>
										<!-- #end -->
										</td>
										<td width="150px">${record.cjsj}</td>
										<td style=" padding: 3px 0 !important;"><select name="state" id="selState" onchange="changeState(${record.rwbh},this.value,'${record.gzap}')" class="selectpicker" data-width="70%">
												<option value="已取消">已取消</option>
												<!-- #if(record.rwzt=="进行中") -->
												<option value="进行中" selected>进行中</option>
												<!-- #else -->
												<option value="进行中">进行中</option>
												<!-- #end -->
												<option value="已完成">已完成</option>
										</select></td>
									</tr>
									<!--#end-->
								</table>
								<div  class="gzce-pagering">
								<ul class="pagination">
									<li><a href="javascript:void(0)" onclick="goToPage(1)">首页</a></li>
									<!-- #if(jxzPageNo==1) -->
									<li class="disabled"><a href="javascript:void(0)">上一页</a></li>
									<!-- #else -->
									<li><a href="javascript:void(0)" onclick="goToPage('${jxzPrevPageNo}')">上一页</a></li>
									<!-- #end -->
									<!-- #if(jxzPageNo==jxzTotalPages) -->
									<li class="disabled"><a href="javascript:void(0)">下一页</a></li>
									<!-- #else -->
									<li><a href="javascript:void(0)" onclick="goToPage('${jxzNextPageNo}')">下一页</a></li>
									<!-- #end -->
									<li><a href="javascript:void(0)" onclick="goToPage('${jxzTotalPages}')">尾页</a></li>
									<li><a>第<input id="txtPageNumber" value="${jxzPageNo}" onkeyup="this.value=this.value.replace(/\D/g,'')" onblur="changePage(this.value)" type="text" />页&nbsp;~&nbsp;共${jxzTotalPages}&nbsp;页/${jxzTotalResults}条
									</a></li>
								</ul>
								</div>
								<!-- #else -->
								<div class="panel-body">没有符合条件的数据</div>
								<!-- #end -->
							<input type="hidden" id="hidPageNo" name="pageNo"/>
							<input type="hidden" id="fjxhidPageNo" name="fjxpageNo"/>
							<br><br>
							<div id="fjxList">
								<div class="panel-heading panel-result-title">
									<h3 class="panel-title">近期任务</h3>
								</div>
								<!-- #set(PaginatedList<HomePageTaskRecord> finishTasks) -->
								<!--
								#set(
								fjxpager= finishTasks.pager,
								fjxtotalResults = fjxpager.getCountOfTotalResults(),
								fjxtotalPages = fjxpager.getCountOfTotalPages() * 1,
								fjxpageSize = fjxpager.pageSize,
								fjxpageNo = fjxpager.pageNo,
								fjxprePageNo = fjxpager.getPrevPageNo(),
								fjxnextPageNo = fjxpager.getNextPageNo()
								)
								#set(date = new Date().format("yyyy-MM-dd"))
								-->
								<!--#if(finishTasks)-->
								<table class="table table-bordered table-hover table-condensed tb" style="text-align: center; border-bottom: 1px solid #DDDDDD;">
									<tr>
										<td>工作安排</td>
										<td>到期时间</td>
										<td>任务状态</td>
										<td>会员名</td>
										<td>手机号</td>
										<td>信息来源</td>
										<td>状态</td>
										<td>子状态</td>
										<td>创建时间</td>
									<tr>
										<!--#for(HomePageTaskRecord record: finishTasks)-->
									<tr>
										<td>${record.gzap}</td>
										<td>${record.dqsj}</td>
										<td>${record.rwzt}</td>
										<td>${record.hyxm}</td>
										<td>${record.hysjh}</td>
										<td>
											<!-- #if(record.xxly=='81') -->
												电话打入
												<!-- #else(record.xxly=='82') -->
												主动拜访
												<!-- #else(record.xxly=='83') -->
												数据库
												<!-- #else(record.xxly=='84') -->
												线上活动
												<!-- #else(record.xxly=='85') -->
												线下活动
												<!-- #else(record.xxly=='86') -->
												其他
												<!-- #else-->
												&nbsp;
												<!-- #end -->
										</td>
										<td>${record.hyzt}</td>
										<td>${record.hyzzt}</td>
										<td>${record.cjsj}</td>
									</tr>
									<!--#end-->
								</table>
								<!-- 列表分页 -->
								<div  class="gzce-pagering">
									<ul class="pagination">
										<li><a href="javascript:void(0)" onclick="fjxgoToPage(1)">首页</a></li>
										<!-- #if(fjxpageNo==1) -->
										<li class="disabled"><a href="javascript:void(0)">上一页</a></li>
										<!-- #else -->
										<li><a href="javascript:void(0)" onclick="fjxgoToPage('${fjxprePageNo}')">上一页</a></li>
										<!-- #end -->
										<!-- #if(fjxpageNo==fjxtotalPages) -->
										<li class="disabled"><a href="javascript:void(0)">下一页</a></li>
										<!-- #else -->
										<li><a href="javascript:void(0)" onclick="fjxgoToPage('${fjxnextPageNo}')">下一页</a></li>
										<!-- #end -->
										<li><a href="javascript:void(0)" onclick="fjxgoToPage('${fjxtotalPages}')">尾页</a></li>
										<li><a>第<input id="fjxtxtPageNumber" value="${fjxpageNo}" onkeyup="this.value=this.value.replace(/\D/g,'')" onblur="fjxchangePage(this.value)" type="text" />页&nbsp;~&nbsp;共${fjxnextPageNo}&nbsp;页/${fjxtotalResults}条
										</a></li>
									</ul>
								</div>
								<!-- #else -->
								<div class="panel-body">没有符合条件的数据</div>
								<!-- #end -->
							</div>
						</div>
					</div>
					</div>
				</div>
			</div>
		</div>
	<div id="td_contact" class="panel-dialog-gzjl panel-radius-all" style="display: none;height:260px;z-index:8;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">创建记录</h3>
			<br> <br>
			<form class="form-horizontal" name="recordForm" action="yueyogaAdmin/addTaskContact.jhtml" method="post">
				<label for="selPerson" class="col-sm-1 control-label">负责人</label>
				<div class="col-sm-8">
					<!-- #set(List<User> respors) -->
					<select class="selectpicker show-menu-arrow" data-live-search="true" data-width="100%" name="resporId" id="selRespors">
						<option value="">&nbsp;</option>
						<!--#for(GroupUserModel u: respors)-->
						<option value="${u.id}">${u.name}</option>
						<!-- #end -->
					</select>
				</div>
				<!-- #if(member.substatus=='0021'||member.substatus=='0022'||member.substatus=='0020'||member.substatus==''||member.substatus==null) -->
				<!-- #else -->
				<br /> <br />
				<label for="selStatusIds" class="col-sm-1 control-label">会员子状态</label>
				<div id="" class="col-sm-8">
					<!-- #set(List<Status> subStatuses) -->
					<select class="selectpicker show-menu-arrow" data-width="100%" name="subStatusCode" id="selStatusIds">
						<option value="">&nbsp;</option>
						<!--#for(Status s:subStatuses)-->
						<option value="${s.code}">${s.name}</option>
						<!-- #end -->
					</select>
				</div>
				<!-- #end -->
				<div id="div_testName" style="display: none;">
					<br /> <br /> <label for="txtTestName" class="col-sm-1 control-label">测试名称</label>
					<div class="col-sm-8">
						<input class="form-control" type="text" id="txtTestName" name="name" />
					</div>
				</div>
				<br /> <br /> <label id="lb_content" for="inputContent" class="col-sm-1 control-label">内容</label>
				<div class="col-sm-8">
					<textarea class="form-control" name="content" id="content" style="resize: none;" rows="2" required>${bz}</textarea>
				</div>
				<input type="hidden" id="hidState" /><input type="hidden" id="hidTaskId" /> <input type="hidden" name="memberId" id="memberId" /> <input type="hidden" name="type" id="hidType" /> <br /> <br /> <br /> <br />
				<div class="panel-btn-search" style="text-align: right; margin-right: 60px;">
					<button id="btnCreateRecord" onclick="createRecord()" type="button" class="btn-adet-default">保存</button>
					&nbsp;&nbsp;&nbsp;
					<button type="button" id="btn_close" onclick="closeDIV()" class="btn-adet-default">取消</button>
				</div>
			</form>
		</div>
	</div>
</body>
<script type="text/javascript">
function documentReady(){
	var msg = "${msg}";
	var subStatus = "${member.substatus}";
	$("#selRespors").val("${resporsId}");
	$("#selStatusIds").val(subStatus);
	var ate = "创建任务失败!";
	var ete = "修改任务失败!";
	var url = "yueyogaAdmin/toMemberTask.jhtml?id="+"${member.memberid}";
	if(msg){
	if(msg=='ate') {
		error(ate);
	}
	if(msg =='ete'){
		error(ete);
	}
 }
	
	//去掉下拉输入框
	$("select").select2({
		width: "100%",
		minimumResultsForSearch: -1
	});
}

	function changeState(taskId,state,subStatusId) {
		var memberId = $("#hidMemberId").val();
		 $("#hidTaskId").val(taskId);
		 $("#hidState").val(state);
		var type ='';
		if(state=='已完成'){
			$("#memberId").val(memberId);
			if(subStatusId=='确认到访'){
				type = '3';
			}else if(subStatusId=='电话联系'){
				type = '4';
			}else if(subStatusId=='等待到访'){
				type = '5';
			}else if(subStatusId=='邀约活动'){
				type = '6';
			}
			else if(subStatusId=='短信跟踪'){
				type = '7';
			}
			else if(subStatusId=='体能测试'){
				type = '8';
			}
			$("#hidType").val(type);
		    if(type=='8'){
				$("#div_testName").show();
				$("#lb_content").text("测试结果");
			}
		    $("#td_contact").slideToggle("normal");
		    //--
		}else{
			//--修改任务状态
			 updateTaskState(memberId,state);
		}
	}
	
	function addTask(){
			var memberId = $("#hidMemberId").val();
			window.location.href = "yueyogaAdmin/toAddTask.jhtml?memberId="
			+ memberId;
	}
	function closeDIV(){
		$("#td_contact").hide("normal");
		var state = $("#").text();
		var memberId = $("#hidMemberId").val();
		window.location.href="yueyogaAdmin/toMemberTask.jhtml?id="+memberId;
	}
	function createRecord(){
		var type = $("#hidType").val();
		var memberId = $("#memberId").val();
		 updateTaskState(memberId);
		var resporId = $("#selRespors").val();
		var content = $("#content").val();
		var name = $("#txtTestName").val();
		var url = "yueyogaAdmin/addTaskContact.jhtml";
		var testUrl = "yueyogaAdmin/toMemberTest.jhtml?id=" + memberId;
		var gzjlUrl = "yueyogaAdmin/toMemberContact.jhtml?id=" + memberId;
		if(type&&type=='8'){
			url = "yueyogaAdmin/addTaskTest.jhtml";
		}
		$("#td_contact").hide();
		$.post(url,{
			memberId:memberId,
			resporId:resporId,
			content:content,
			type:type,
			name:name
		}, function(res) {
			res = eval("("+res+")");
			if(res.success) {
				//--修改任务状态
				if(type=='8'){
					window.location.href = testUrl;
				}else{
					window.location.href = gzjlUrl;
				}
			} else {
				error(res.msg);
			}
		});
		
	}
	$(function() {
		var ids = [];
		//删除
		$("#btn_delete").click(function() {
			$('input[name="chk_name"]:checked').each(function() {
				ids.push($(this).val());
			});
			if (ids.length == 0) {
				alert("请选择要删除的记录!");
				return;
			}else if(ids.length > 0){
				confirm("确定要删除吗?",function(){
					this.close();
					var d = wait("正在删除，请稍候...");
					var url = "yueyogaAdmin/deleteTasksByIds.jhtml?ids=" + ids;
					$.post(url, function(msg) {
						if (msg == 'true') {
							d.content("删除成功!");
							setTimeout(function(){
							d.close().remove();
							window.location.reload();
							}, 400);
							 $("input[name='chk_name']").prop("checked",false);
						} else {
							error("删除失败!");
						}
					});
				});
			}
		});
		$("#btn_edit").click(function() {
			$('input[name="chk_name"]:checked').each(function() {
				ids.push($(this).val());
			});
			if (ids.length == 1) {
				window.location.href = "yueyogaAdmin/toEditTask.jhtml?taskId="+ ids;
			} else {
				alert("请选择一条记录进行修改!");
			}
			ids = [];
		});
		
		//--全选`反选
		$("#chkallIds").click(function() {
			if (this.checked) {
				$("input[name='chk_name']").each(function() {
					this.checked = true;
				});
			} else {
				$("input[name='chk_name']").each(function() {
					this.checked = false;
				});
			}
		});
	});
function updateTaskState(memberId,state){
	var url = "yueyogaAdmin/updateTaskByTaskId.jhtml"; 
	var taskId = $("#hidTaskId").val();
	var state = $("#hidState").val();
	var hyzzt = $("#selStatusIds").val();
	var nstate = '';
	if(state=='已完成'){
		nstate ='2';
	}else if(state=='已取消'){
		nstate ='0';
	}else{
		nstate ='1';
	}
	$.post(url,
		{
			taskId : taskId,
			memberId : memberId,
			state : nstate,
			subStatus:hyzzt
		}, 
		function(msg) {
			if (msg == '修改任务状态失败!') {
				error(msg);
			}else{
				if(state!='已完成'){
					$("#selState").val("进行中");
					window.location.reload();
				}
			}
	});
}

function changePage(value) {
	value = value * 1;
	var newval = value;
	var totalPages = '${jxzTotalPages}';
	if (value > totalPages) {
		value = totalPages;
	} else if (value < 1) {
		value = 1;
	}
	$("#txtPageNumber").val(value);
	if(newval > totalPages || newval < 1){
		return;
	}
	goToPage(value);
}
function goToPage(pageNo) {
	var memberId = $("#hidMemberId").val();
	$("#hidPageNo").val(pageNo);
	window.location.href = "yueyogaAdmin/toMemberTask.jhtml?id="+memberId+"&pageNo="+pageNo;
}
function fjxchangePage(value) {
	value = value * 1;
	var newval = value;
	var totalPages = '${fjxtotalPages}';
	if (value > totalPages) {
		value = totalPages;
	} else if (value < 1) {
		value = 1;
	}
	$("#fjxtxtPageNumber").val(value);
	if(newval > totalPages || newval < 1){
		return;
	}
	fjxgoToPage(value);
}
function fjxgoToPage(pageNo) {
	var memberId = $("#hidMemberId").val();
	$("#fjxhidPageNo").val(pageNo);
	window.location.href = "yueyogaAdmin/toMemberTask.jhtml?id="+memberId+"&fjxpageNo="+pageNo;
}
</script>
</html>
